<%@ page language="java" contentType="text/html;charset=UTF-8" %>
<%@ include file="/static/include/taglib.jsp" %>
<html>
<head>
    <title>Title</title>
    <link href="${ctxStatic}/layui/css/layui.css" rel="stylesheet"/>
    <link href="${ctxStatic}/css/kpiui.css" rel="stylesheet"/>
    <script src="${ctxStatic}/js/jquery-1.8.3.min.js?v=2.0" type="text/javascript"></script>
    <script src="${ctxStatic}/layui/layui.all.js" type="text/javascript"></script>
    <script src="${ctxStatic}/js/common.js" type="text/javascript"></script>

    <style>

        .text-center {

            text-align: center;
        }

        .layui-table-cell {
            /*height: 28px;*/ /*注释掉*/
            height: auto; /*新添加的*/
            line-height: 28px;
            /* padding: 0 15px; */
            position: relative;
            overflow: hidden;
            /* text-overflow: ellipsis; */
            white-space: normal;
            box-sizing: border-box;
        }

        .tableTitle {

            text-align: center;
        }

        table {
            color: rgba(255, 186, 0, 1);;
        }
    </style>
</head>
<body>

<div class="serchcontent" style="margin: 20px 20px">
    <div class="search">
        <div class="layui-form">
            <table>
                <tr>
                    <td class="td_select">
                        <select id="year" placeholder="年份" lay-filter="year">

                        </select>
                        <input type="hidden" id="hidyear" value="${year }">
                    </td>
                    <td class="td_select">
                        <select id="month" lay-filter="month">
                            <option value="1">1季度</option>
                            <option value="2">2季度</option>
                            <option value="3">3季度</option>
                            <option value="4">4季度</option>

                        </select>
                        <input type="hidden" id="hidquarter" value="${quarter}">
                    </td>
                    <td style="text-align: center;width:280px">
                        <button class="button" onclick="search()"><img
                                src="${ctxStatic}/images/button/chaxun.png" style="width:20px">查询
                        </button>


                        <button class="button" onclick="saveOpinion()"> 保存
                        </button>


                        <button class="button" onclick="excle()"> 导出
                        </button>
                    </td>
                </tr>
            </table>
        </div>
    </div>

    <div>
        <div class="tableTitle">
            <h3>北京市公安局房山分局</h3>
            <h3>公务员平时考核结果统计表</h3>
            （<span class="titleYear"></span> 年&nbsp;&nbsp;<span class="fitstM"></span>月- <span
                class="lastM"></span>
            月）

        </div>

        <table cellspacing="0" cellpadding="0" border="0" class="layui-table" style="margin:0;">

            <thead style="color:  rgba(255,186,0,1);">

            <tr>
                <th rowspan="2" colspan="2"></th>
                <th rowspan="2" style="text-align: center">实有人数</th>
                <th colspan="4" style="text-align: center">参加考核人数</th>
                <th rowspan="2" style="text-align: center;width: 100px">未参加考核人数</th>
                <th rowspan="2" style="text-align: center;width: 100px">不定考核结果</th>

            </tr>
            <tr>
                <th>小计</th>
                <th>好</th>
                <th>合格</th>
                <th>差</th>
            </tr>

            </thead>

            <tbody>
            <tr>
                <th colspan="2">合计</th>
                <th class="1hj"></th>
                <th class="2hj"></th>
                <th class="3hj"></th>
                <th class="4hj"></th>
                <th class="5hj"></th>
                <th class="6hj"></th>
                <th class="7hj"></th>
            </tr>
            <tr>
                <td rowspan="4">处级及以下公务员</td>
                <td>处级领导干部</td>
                <td class="1s   1hjd "></td>
                <td class="1x filed  2hjd"></td>
                <td class="1g filed  3hjd"></td>
                <td class="1h filed   4hjd"></td>
                <td class="1c  filed 5hjd"></td>
                <td class="1w filed  6hjd"></td>
                <td class="1b filed  7hjd"></td>

            </tr>
            <tr>
                <td>科级领导干部</td>
                <td class="2s  1hjd "></td>
                <td class="2x filed   2hjd"></td>
                <td class="2g filed 3hjd "></td>
                <td class="2h filed   4hjd"></td>
                <td class="2c filed  5hjd "></td>
                <td class="2w filed  6hjd "></td>
                <td class="2b filed   7hjd"></td>
            </tr>
            <tr>
                <td>民警</td>
                <td class="3s  1hjd "></td>
                <td class="3x filed  2hjd "></td>
                <td class="3g filed   3hjd "></td>
                <td class="3h filed  4hjd"></td>
                <td class="3c filed  5hjd "></td>
                <td class="3w filed   6hjd"></td>
                <td class="3b filed   7hjd"></td>
            </tr>
            <tr>
                <td>未定职务(新录用公务员)</td>
                <td class="4s  1hjd "></td>
                <td class="4x filed  2hjd "></td>
                <td class="4g filed   3hjd"></td>
                <td class="4h filed  4hjd "></td>
                <td class="4c filed    5hjd"></td>
                <td class="4w filed  6hjd"></td>
                <td class="4b filed  7hjd "></td>
            </tr>
            <tfooter>


                <tr>
                    <td>局属单位党委审核意见</td>
                    <td colspan="8"><textarea id="opinion" class="entityFiled"
                                              style="margin: 0px; width: 100%; height: 87px;    color: rgba(255,255,255,0.80);
    background: #2A68A6;
    border: 1px solid #589DF5;"></textarea>
                    </td>
                </tr>

                <tr>
                    <td>电话</td>
                    <td colspan="8">
                        <input id="phone" class="entityFiled"
                               style=" width: 100%; color: rgba(255,255,255,0.80);background: #2A68A6;border: 1px solid #589DF5;"></input>
                    </td>
                </tr>
            </tfooter>
            </tbody>
        </table>
    </div>

</div>
</div>
</body>
<script>
    var year = new Date().getFullYear();
    var quarter = getQuarter();
    var opinion;

    function getYear() {

        var year = new Date().getFullYear() - 1;
        $("#year").append("<option value=" + year + ">" + year + '年' + "</option>");
        $("#year").append("<option   selected  value=" + new Date().getFullYear() + ">" + new Date().getFullYear() + '年' + "</option>");


    }

    function getQuarter() {

        var month = new Date().getMonth() + 1;

        if (month <= 3) {

            return 1;

        } else if (month <= 6) {

            return 2 - 1;

        } else if (month <= 9) {

            return 3 - 1;

        } else if (month <= 12) {

            return 4 - 1;

        }

    };
    $(function () {

        $('.entityFiled').on('change', function () {
            saveOpinion(function () {
                top.mylayui.msg('已自动保存', {icon: 1});

            });
        })

        if ($('#hidyear').val() > 0) {

            $('.search').hide();
            year = $('#hidyear').val();
            quarter = $('#hidquarter').val();
            $('.tableTitle').hide();
        } else {
            $('.search').show();
            $('.tableTitle').show();


        }


        getYear();
        if (quarter == 1) {
            year = new Date().getFullYear() - 1;
            $('#year').val(year);
            quarter = 4;


        }
        $('#month').val(quarter)
        search(year, quarter);
        setTitle({value: quarter});
        setTitleYear({value: year});

        var form;
        layui.use('form', function () {
            form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
            form.render();
        });


        form.on('select(year)', function (data) {

            setTitleYear(data);
            year = data.value;
            search(year, quarter);
        });
        form.on('select(month)', function (data) {

            setTitle(data);
            quarter = data.value;
            search(year, quarter);
        })
    })


    function setTitleYear(data) {

        $('.titleYear').text(data.value);

    }

    function setTitle(data) {

        if (data.value == 1) {
            $('.fitstM').text(1);
            $('.lastM').text(3);

        } else if (data.value == 2) {
            $('.fitstM').text(4);
            $('.lastM').text(6);

        } else if (data.value == 3) {

            $('.fitstM').text(7);
            $('.lastM').text(9);
        } else {
            $('.fitstM').text(10);
            $('.lastM').text(12);
        }
    }

    function search() {

        $.ajax({
            type: "POST",
            url: "get_list",
            data: {
                year: year,
                quarter: quarter
            },
            beforeSend: function (XHR) {
            },
            success: function (data) {
                data = eval('(' + data + ')');
                opinion = data.pskhOpinion;
                if (opinion) {
                    $('#opinion').val(opinion.opinion);
                    $('#phone').val(opinion.phone);
                } else {
                    $('#opinion').val('');
                    $('#phone').val('');
                }
                $('.filed').text('');
                var result = data.newPSKHS;
                for (var i = 0; i < result.length; i++) {
                    var element = result[i];
                    setTableContent(element);

                    // switch (element.rank) {
                    //
                    //     case '1':
                    //         setText(1, element.zpjg, element.num)
                    //
                    //         break;
                    //     case '2':
                    //         setText(2, element.zpjg, element.num)
                    //
                    //         break;
                    //     case '3':
                    //         setText(3, element.zpjg, element.num)
                    //
                    //         break;
                    //     case '4':
                    //         setText(4, element.zpjg, element.num)
                    //
                    //         break;
                    //
                    //
                    // }

                }


                var bdjk = data.bdjg;


                var userCounts = data.userCounts;


                for (var i = 0; i < userCounts.length; i++) {
                    var element = userCounts[i];
                    setUserCOunt(element.rank, element.num)
                }
                xiaoji();
                heji();

            },
            complete: function (XHR) {

            },
            error: function () {

            }
        });
    }

    function excle() {
        var index = layer.load();
        $.ajax({
            type: "POST",
            url: "peace_export",
            data: {
                year: year,
                quarter: quarter
            },
            beforeSend: function (XHR) {
            },
            success: function (data) {
                data = eval('(' + data + ')');
                if (data.result > 0) {
                    //top.mylayui.msg('导出成功', {icon: 1});
                    //document.location.reload();
                    window.open(data.msg, '_self');
                }
                else {
                    top.mylayui.msg(data.msg, {icon: 0});
                }
            },
            complete: function (XHR) {
                layer.close(index);
            },
            error: function () {
                layer.close(index);
            }
        });
    }

    function calculationCount(rank) {

        var sj = $('.' + rank + 's').text();
        if (checkText(sj) > 0) {

            var good = $('.' + rank + 'g').text();
            var hege = $('.' + rank + 'h').text();
            var cha = $('.' + rank + 'c').text();
            // var wei = sj - checkText(good) - checkText(hege) - checkText(cha);

            // if (checkText(wei) > 0)
            //     $('.' + rank + 'w').text(wei)

        }

    }

    function checkText(text) {
        if (text == '' || text == null || text == undefined)

            return 0
        else
            return text;

    }


    function setUserCOunt(rank, num) {


        $('.' + rank + 's').text(num)
        calculationCount(rank);
    }


    function setTableContent(obj) {


        $('.' + obj.rank + 'h').text(checkText(obj.hege));
        $('.' + obj.rank + 'g').text(checkText(obj.hao));
        $('.' + obj.rank + 'c').text(checkText(obj.cha));
        $('.' + obj.rank + 'b').text(checkText(obj.bddc));

        $('.' + obj.rank + 'w').text(checkText(obj.bcj))


    }


    function setText(rank, result, num) {

        if (result == '合格') {

            $('.' + rank + 'h').text(num)
        } else if (result == '好') {

            $('.' + rank + 'g').text(num)

        } else if (result == '差') {
            $('.' + rank + 'c').text(num)

        } else if (result == '不定考核结果') {

            $('.' + rank + 'b').text(num)

        } else if (result == '不参加') {

            $('.' + rank + 'w').text(num)

        }
    }

    function xiaoji() {
        for (var i = 1; i < 5; i++) {

            var good = $('.' + i + 'g').text();
            var hege = $('.' + i + 'h').text();
            var cha = $('.' + i + 'c').text();
            var xj = parseInt(checkText(good)) + parseInt(checkText(hege)) + parseInt(checkText(cha));
            $('.' + i + 'x').text(checkText(xj) > 0 ? xj : '');

        }

    }

    function heji() {

        for (var i = 1; i < 8; i++) {

            var nodes = $('.' + i + 'hjd');
            var num = 0;
            for (var j = 0; j < nodes.length; j++) {
                num = num + parseInt(checkText($(nodes[j]).text()))

            }
            $('.' + i + 'hj').text(checkText(num) > 0 ? num : '');

        }
    }


    function saveOpinion(callback) {


        $.ajax({
            type: "POST",
            url: "saveOpinion",
            data: {
                id: opinion == null || opinion == undefined ? 0 : opinion.id,
                opinion: $('#opinion').val(),
                year: year,
                quarter: quarter,
                phone: $('#phone').val()

            },
            beforeSend: function (XHR) {

            },
            success: function (data) {
                if (callback)
                    callback();
                else
                    top.mylayui.msg('保存成功', {icon: 1});

            },
            complete: function (XHR) {

            },
            error: function () {

            }
        });


    }


</script>
</html>
